package com.itfenghuang.day13;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class A05_Server服务端 {
/*
    实现步骤
        1.创建ServerSocket对象
        2.监听链接  accept
        3.获取输入流对象
        4.接收客户端消息
        5.获取输出流对象
        6.回送消息
        7.释放资源
 */
    public static void main(String[] args) throws IOException {
//        1.创建ServerSocket对象
        ServerSocket ss = new ServerSocket(10086);
//        2.监听链接  accept
        Socket socket = ss.accept();
//        3.获取输入流对象
        InputStream is = socket.getInputStream();
//        4.接收客户端消息
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        System.out.println(new String(bys,0,len));
//        5.获取输出流对象
        OutputStream os = socket.getOutputStream();
//        6.回送消息
        os.write("大傻子".getBytes());
//        7.释放资源
            ss.close();
    }
}
